/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, {
/******/ 				configurable: false,
/******/ 				enumerable: true,
/******/ 				get: getter
/******/ 			});
/******/ 		}
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 2);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {

module.exports = require("react");

/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";


var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var State_ = function () {
    function State_() {
        _classCallCheck(this, State_);

        if (arguments && arguments[0]) {
            this.money = arguments[0];
        } else {
            this.money = 1000;
        }
    }

    _createClass(State_, [{
        key: "getMoney",
        value: function getMoney() {
            return this.money;
        }
    }, {
        key: "buy",
        value: function buy() {
            this.money -= 100;
        }
    }, {
        key: "reset",
        value: function reset(number) {
            this.money = number;
        }
    }]);

    return State_;
}();

var State = new State_(10000);

module.exports = State;

/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
/* WEBPACK VAR INJECTION */(function(__dirname) {

var _http = __webpack_require__(3);

var _react = __webpack_require__(0);

var _react2 = _interopRequireDefault(_react);

var _server = __webpack_require__(4);

var _server2 = _interopRequireDefault(_server);

var _reactRouter = __webpack_require__(5);

var _App = __webpack_require__(6);

var _App2 = _interopRequireDefault(_App);

var _express = __webpack_require__(12);

var _express2 = _interopRequireDefault(_express);

var _path = __webpack_require__(13);

var _path2 = _interopRequireDefault(_path);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var app = (0, _express2.default)();

app.use(_express2.default.static(_path2.default.join(__dirname, 'public')));

app.get('/age', function (req, resp) {
    resp.send('{\'age\': 1991}');
    resp.end();
});

app.get('/number/:number', function (req, res) {
    var sid = getCookieNumber(req, res, true);
    var newNumber = req.params.number;
    console.log('syncNumber ' + sid + " = " + newNumber);
    cookieManager[sid] = newNumber;
    res.send('{"msg":"ok"}');
    res.end();
});

app.get('*', dealRequest);

function dealRequest(req, res) {
    var context = {};
    var number = getCookieNumber(req, res);
    console.log('number = ' + number);
    var html = _server2.default.renderToString(_react2.default.createElement(
        _reactRouter.StaticRouter,
        {
            location: req.url,
            context: context
        },
        _react2.default.createElement(_App2.default, { number: number })
    ));
    var script_ = 'var NUMBER = ' + number;

    var html_ = _server2.default.renderToStaticMarkup(_react2.default.createElement(
        'html',
        null,
        _react2.default.createElement(
            'head',
            null,
            _react2.default.createElement('link', { rel: 'stylesheet', href: __dirname + '/style.css' })
        ),
        _react2.default.createElement(
            'body',
            null,
            _react2.default.createElement('div', { id: 'app', dangerouslySetInnerHTML: { __html: html } }),
            _react2.default.createElement('script', { dangerouslySetInnerHTML: { __html: script_ } }),
            _react2.default.createElement('script', { src: __dirname + '/main.js' })
        )
    ));

    if (context.url) {
        console.log('redirect -> ' + context.url);
        res.writeHead(301, {
            Location: context.url
        });
        res.end();
    } else {
        res.write(html_);
        res.end();
    }
}

var cookieManager = {};

function getCookieNumber(req, res, justSid) {
    var ck = req.headers.cookie;
    if (ck) {
        var cks = ck.split(';');
        var sid = 0;
        for (var i = 0; i < cks.length; i++) {
            var pairs = cks[i].split('=');
            if (pairs[0].trim() == 'sid') {
                sid = pairs[1];
            }
        }
    }
    if (justSid) {
        return sid;
    }
    if (sid) {
        if (cookieManager[sid]) {
            console.log('sid = ' + sid);
            return cookieManager[sid];
        }
    } else {
        sid = generateSid();
    }
    console.log('sid = ' + sid);
    cookieManager[sid] = 10000;
    res.cookie('sid', sid);
    return 10000;
}

function generateSid() {
    var tmpId = parseInt(Math.random() * 100000);
    if (cookieManager[tmpId]) {
        return generateSid();
    }
    return tmpId;
}

app.listen(3000);
/* WEBPACK VAR INJECTION */}.call(exports, ""))

/***/ }),
/* 3 */
/***/ (function(module, exports) {

module.exports = require("http");

/***/ }),
/* 4 */
/***/ (function(module, exports) {

module.exports = require("react-dom/server");

/***/ }),
/* 5 */
/***/ (function(module, exports) {

module.exports = require("react-router");

/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";


Object.defineProperty(exports, "__esModule", {
    value: true
});

var _react = __webpack_require__(0);

var _react2 = _interopRequireDefault(_react);

var _reactRouterDom = __webpack_require__(7);

var _State = __webpack_require__(1);

var _State2 = _interopRequireDefault(_State);

var _App = __webpack_require__(8);

var _App2 = _interopRequireDefault(_App);

var _App3 = __webpack_require__(9);

var _App4 = _interopRequireDefault(_App3);

var _App5 = __webpack_require__(10);

var _App6 = _interopRequireDefault(_App5);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var App = function App(_ref) {
    var number = _ref.number;

    _State2.default.reset(number);
    return _react2.default.createElement(
        'div',
        null,
        _react2.default.createElement(
            'li',
            null,
            _react2.default.createElement(
                _reactRouterDom.Link,
                { to: '/a1' },
                'A1'
            )
        ),
        _react2.default.createElement(
            'li',
            null,
            _react2.default.createElement(
                _reactRouterDom.Link,
                { to: '/a2' },
                'A2'
            )
        ),
        _react2.default.createElement(
            'li',
            null,
            _react2.default.createElement(
                _reactRouterDom.Link,
                { to: '/a1/a2' },
                'A1/A2'
            )
        ),
        _react2.default.createElement(
            'li',
            null,
            _react2.default.createElement(
                _reactRouterDom.Link,
                { to: '/a3' },
                'A3->A1/A2'
            )
        ),
        _react2.default.createElement(
            _reactRouterDom.Switch,
            null,
            _react2.default.createElement(_reactRouterDom.Route, { path: '/a1', exact: true, component: _App2.default }),
            _react2.default.createElement(_reactRouterDom.Route, { path: '/a2', component: _App4.default }),
            _react2.default.createElement(_reactRouterDom.Route, { path: '/a1/a2', component: _App6.default }),
            _react2.default.createElement(_reactRouterDom.Redirect, { to: '/a1/a2' })
        )
    );
};

exports.default = App;

/***/ }),
/* 7 */
/***/ (function(module, exports) {

module.exports = require("react-router-dom");

/***/ }),
/* 8 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";


Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.App1 = undefined;

var _react = __webpack_require__(0);

var _react2 = _interopRequireDefault(_react);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

console.log('App1 is required...');

var App1 = exports.App1 = function App1() {
    return _react2.default.createElement(
        'div',
        null,
        'App1'
    );
};

/***/ }),
/* 9 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";


Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.App2 = undefined;

var _react = __webpack_require__(0);

var _react2 = _interopRequireDefault(_react);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

console.log('App2 is required...');

var App2 = exports.App2 = function App2() {
    return _react2.default.createElement(
        'div',
        null,
        'App2'
    );
};

/***/ }),
/* 10 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";


Object.defineProperty(exports, "__esModule", {
    value: true
});

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = __webpack_require__(0);

var _react2 = _interopRequireDefault(_react);

var _isomorphicFetch = __webpack_require__(11);

var _isomorphicFetch2 = _interopRequireDefault(_isomorphicFetch);

var _State = __webpack_require__(1);

var _State2 = _interopRequireDefault(_State);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

console.log('App12 is required...');

var App12 = function (_React$Component) {
    _inherits(App12, _React$Component);

    function App12(props) {
        _classCallCheck(this, App12);

        var _this = _possibleConstructorReturn(this, (App12.__proto__ || Object.getPrototypeOf(App12)).call(this, props));

        _this.state = {
            age: 26,
            money: _State2.default.getMoney()
        };
        return _this;
    }

    _createClass(App12, [{
        key: 'testClick',
        value: function testClick() {
            this.setState(_extends({}, this.state, {
                age: this.state.age + 1
            }));
        }
    }, {
        key: 'buy',
        value: function buy() {
            _State2.default.buy();
            this.setState(_extends({}, this.state, {
                money: _State2.default.getMoney()
            }));
            var url = 'http://127.0.0.1:3000/number/' + _State2.default.getMoney();
            (0, _isomorphicFetch2.default)(url, { credentials: 'include' }).then(function (response) {
                return response.json();
            }).then(function (json) {
                return console.log(json);
            });
        }
    }, {
        key: 'render',
        value: function render() {
            return _react2.default.createElement(
                'div',
                null,
                _react2.default.createElement(
                    'div',
                    { style: { color: '#f00', background: '#0f0' }, onClick: this.buy.bind(this) },
                    this.state.money
                ),
                _react2.default.createElement('br', null),
                _react2.default.createElement(
                    'div',
                    { style: { color: '#0f0', background: '#f00' }, onClick: this.testClick.bind(this) },
                    this.state.age
                )
            );
        }
    }]);

    return App12;
}(_react2.default.Component);

exports.default = App12;

/***/ }),
/* 11 */
/***/ (function(module, exports) {

module.exports = require("isomorphic-fetch");

/***/ }),
/* 12 */
/***/ (function(module, exports) {

module.exports = require("express");

/***/ }),
/* 13 */
/***/ (function(module, exports) {

module.exports = require("path");

/***/ })
/******/ ]);